
import subprocess
from ..config.config import workflow_dir
def dealWorkShell(_shellDir,_L01Dir,_samples,_lane,bclDir,runid,outdir,rawsamplesDir): 
  with open(f'{_L01Dir}/work.sh','w') as out:
    for i, e in _samples.items():
      # 若对应样本的文件夹不存在则创建
      lane = _lane[i].split('&')
      # 如果每个I7Index只对应一条lane 将
      if len(lane) == 1:
        x = lane[0][1]
        z = f'L0{x}'
        out.write(f'cat {bclDir}/L0{x}/{runid}_L0{x}_{i}.fq.gz > {_L01Dir}/{e}_{i}.fq.gz\n')
      else:
        fqs = ' '.join([f'{bclDir}/L0{j[1]}/{runid}_L0{j[1]}_{i}.fq.gz' for n, j in enumerate(lane)])
        out.write(f'cat {fqs} > {_L01Dir}/{e}_{i}.fq.gz\n')
      subprocess.run(f'ln -s {str(outdir)}/L01/{e}_{i}.fq.gz {str(rawsamplesDir[e])}', shell=True)
  with open(f'{_shellDir}/all.cnv.sh', 'w') as cnv:
        cnv.write(f'''sh {workflow_dir}/cnv/run_cnv.sh {runid}
sh {workflow_dir}/run_cnvseq.sh {runid} \n''')   